

import java.io.IOException;
import java.sql.*;
import java.util.*;

public class JdbcUtil {
    //数据库用户名
    private static final String USERNAME = "root";
    //数据库密码
    private static final String PASSWORD = "xxxxxx";
    //驱动信息
    private static final String DRIVER = "com.mysql.jdbc.Driver";
    //数据库地址
    private static final String URL = "jdbc:mysql://localhost:3306/oversea?characterEncoding=utf-8";

    private static Stack<Connection> stack = new Stack<Connection>();

    static {
        try {
            Class.forName(DRIVER);
            System.out.println("初始化一个连接池！");
            for (int i = 0; i < 30; i++) {
                stack.push(DriverManager.getConnection(URL, USERNAME, PASSWORD));
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }


    /**
     * 获得数据库的连接
     *
     * @return
     */
    public static Connection getConnection()  {
            while(stack.size()==0){
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        return stack.pop();
    }

    /**
     * 释放数据库连接
     */
    public static void releaseConn(Connection conn) {
        stack.push(conn);
    }

    /**
     * @param args
     */
    public static void main(String[] args) throws SQLException, IOException {
        // TODO Auto-generated method stub
        for (int i = 0; i < 100; i++) {
            System.out.println("ALTER TABLE `overseas1`.`offer"+i+"` CHANGE COLUMN `image` `image` varchar(512);");
        }
    }
}